﻿using SRV.ServiceInterface;
using SRV.ViewModel.Email;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace _17bangMVC.Controllers
{
    public class EmailController : Controller
    {
        private IUserService userService;
        public EmailController(IUserService userService)
        {
            this.userService = userService;
        }
        // GET: Email
        public ActionResult Activate()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Activate(ActivateModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            userService.GetEmail(model);
            return View(model);
        }
        //验证Email注册成功
        [HttpGet]
        public ActionResult Validate(int uid, string code)
        {
            ActivateModel model = userService.GetEmailCode(uid);
            if (code != model.Code)
            {
                ModelState.AddModelError("Email", "*验证码错误");
                return View();
            }
            userService.ValidEmail(uid);
            ViewBag.Succeed = true;
            return View();
        }
    }
}
